import tensorflow as tf
import os
from common import show_picture

if __name__ == '__main__':
    os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2'
    image_path = './lenna.png'

    # 读取图片数据
    image = tf.io.read_file(image_path)
    image = tf.image.decode_png(image)

    show_picture(image, 'lenna.png')

    # 改变图像亮度
    # bright_img = tf.image.adjust_brightness(image, 0)
    # show_picture(bright_img, 'bright_img')
    # float_image = tf.image.convert_image_dtype(image, tf.float32)
    # saturated_img = tf.image.adjust_saturation(image,  0.6)  # 改变图像饱和度
    # show_picture(saturated_img, 'saturated_img')

    # 改变对比度
    contrasted_img = tf.image.adjust_contrast(image, 2)
    show_picture(contrasted_img, 'contrasted_img')
    # # 编码为tensor格式
    # encoded_image = tf.image.encode_jpeg(contrasted_img)
    # # 将编码后的图片保存到指定路径
    # with tf.io.gfile.GFile('./images/0001.jpg', 'wb') as file:
    #     file.write(encoded_image.numpy())